from math import sqrt,cos,sin,radians
from tkinter import *
from tkinter import ttk
#code is very teribble, i think. but there are many comments!

WIDHT=900
HEIGHT=900

#func for creating easy to use positions for canvas
#
# wq  w   we
# a   sw  d
# sa  s   sd
wq,w,we,a,sw,d,sa,s,sd=0,0,0,0,0,0,0,0,0
def positions(wid,hei):
    global wq,w,we,a,sw,d,sa,s,sd
    wq = 0,hei ; w = wid/2,hei ; we = wid,hei
    a = 0,hei/2 ; sw = wid/2,hei/2 ; d = wid,hei/2
    sa = 0,0 ; s = wid/2,0 ; sd = wid,0
positions(WIDHT,HEIGHT)

#window
window = Tk()
window.geometry("{0}x{1}".format(WIDHT,HEIGHT))
window.title("vector")
window.config(background="gray")
#canvas settings
canvas = Canvas(bg="orange", width=WIDHT, height=HEIGHT)
canvas.pack(anchor=CENTER, expand=1)
#static sprites
canvas.create_line(a,d)
canvas.create_line(w,s)
k=int(sw[0]);p=int(sw[1])
canvas.create_oval(k/2,p/2,k*1.5,p*1.5)

# Set dot on oval end make it move by arrow keys right,left
#
#change coords from 4 par to 2 par (return x,y or center)
def dcrd(li):
    ax,ay,bx,by=map(int, li)
    x = (ax-bx)/2
    if x<0: x*=-1
    y = (ay-by)/2
    if y<0: y*=-1
    return x,y

#set dot or oval by center
def dstc(x,y,rad=4):
    ax = x-rad
    ay = y-rad
    bx = x+rad
    by = y+rad
    return ax, ay, bx, by

#making canvas object (line,oval,text)
dot_ov = canvas.create_oval(dstc(k*1.5,p),fill="white",outline="gray")
sin_line_ov = canvas.create_line(k, p, k+WIDHT/4, p, fill="red", width=2)
cos_line_ov = canvas.create_line(k, p, k+WIDHT/4, p, fill="blue", width=2)
gip_line_ov = canvas.create_line(k, p, k+WIDHT/4, p, fill="black", width=1)
angel_text_ov = canvas.create_text(k+4, p-17, font="Arial 13", anchor=NW, text="/a = 0", fill="green")
cos_text_ov = canvas.create_text(k,p, font="Arial 13", anchor=NW, text="cos/a = 1", fill="blue")
sin_text_ov = canvas.create_text(k+WIDHT/4, p, font="Arial 13", anchor=NW, text="sin/a = 0", fill="red")


#move dot on oval; big part of prog
cnt = 0
howm = 10
def ovaldot(event):
    if event.keysym == "Right":
        global cnt,howm; mn = 50625; cnt+=howm
        crd = canvas.coords(dot_ov)
        if cnt <= 90:
            #! 90
            xxx=sqrt(((cos(radians(cnt)))**2)*mn)
            yyy=sqrt(((sin(radians(cnt)))**2)*mn)
        
            canvas.coords( dot_ov, dstc( k+xxx , p-yyy ) )
            canvas.coords( sin_line_ov, k+xxx, p, k+xxx, p-yyy )
            canvas.coords( cos_line_ov, k, p, k+xxx, p )
            canvas.coords( gip_line_ov, k, p, k+xxx, p-yyy )
            canvas.coords( sin_text_ov, k+xxx, p-yyy )
            canvas.coords( cos_text_ov, k, p )
            canvas.coords( angel_text_ov, k+4, p-17 )
            canvas.itemconfigure( cos_text_ov, text="cos/a = {0}".format(round(cos(radians(cnt)),6)))
            canvas.itemconfigure( sin_text_ov, text="sin/a = {0}".format(round(sin(radians(cnt)),6)))
            canvas.itemconfigure( angel_text_ov, text="/a = {0}".format(cnt))
        elif cnt <= 180:
            #! 180
            xxx=sqrt(((cos(radians(cnt)))**2)*mn)
            yyy=sqrt(((sin(radians(cnt)))**2)*mn)
        
            canvas.coords( dot_ov, dstc( k-xxx , p-yyy ) )
            canvas.coords( sin_line_ov, k-xxx, p, k-xxx, p-yyy )
            canvas.coords( cos_line_ov, k, p, k-xxx, p )
            canvas.coords( gip_line_ov, k, p, k-xxx, p-yyy )
            canvas.coords( sin_text_ov, k-xxx, p-yyy )
            canvas.coords( cos_text_ov, k-xxx, p )
            canvas.coords( angel_text_ov, k-70, p-17 )
            canvas.itemconfigure( cos_text_ov, text="cos/a = {0}".format(round(cos(radians(cnt)),6)))
            canvas.itemconfigure( sin_text_ov, text="sin/a = {0}".format(round(sin(radians(cnt)),6)))
            canvas.itemconfigure( angel_text_ov, text="/a = {0}".format(cnt))
        elif cnt <= 270:
            #! 270
            xxx=sqrt(((cos(radians(cnt)))**2)*mn)
            yyy=sqrt(((sin(radians(cnt)))**2)*mn)
        
            canvas.coords( dot_ov, dstc( k-xxx , p+yyy ) )
            canvas.coords( sin_line_ov, k-xxx, p, k-xxx, p+yyy )
            canvas.coords( cos_line_ov, k, p, k-xxx, p )
            canvas.coords( gip_line_ov, k, p, k-xxx, p+yyy )
            canvas.coords( sin_text_ov, k-xxx, p+yyy )
            canvas.coords( cos_text_ov, k-xxx, p-18 )
            canvas.coords( angel_text_ov, k-70, p )
            canvas.itemconfigure( cos_text_ov, text="cos/a = {0}".format(round(cos(radians(cnt)),6)))
            canvas.itemconfigure( sin_text_ov, text="sin/a = {0}".format(round(sin(radians(cnt)),6)))
            canvas.itemconfigure( angel_text_ov, text="/a = {0}".format(cnt))
        elif cnt <= 360:
            #! 360
            xxx=sqrt(((cos(radians(cnt)))**2)*mn)
            yyy=sqrt(((sin(radians(cnt)))**2)*mn)
        
            canvas.coords( dot_ov, dstc( k+xxx , p+yyy ) )
            canvas.coords( sin_line_ov, k+xxx, p, k+xxx, p+yyy )
            canvas.coords( cos_line_ov, k, p, k+xxx, p )
            canvas.coords( gip_line_ov, k, p, k+xxx, p+yyy )
            canvas.coords( sin_text_ov, k+xxx, p+yyy )
            canvas.coords( angel_text_ov, k, p )
            canvas.itemconfigure( cos_text_ov, text="cos/a = {0}".format(round(cos(radians(cnt)),6)))
            canvas.itemconfigure( sin_text_ov, text="sin/a = {0}".format(round(sin(radians(cnt)),6)))
            canvas.itemconfigure( angel_text_ov, text="/a = {0}".format(cnt))
            if cnt == 360: cnt = 0
    if event.keysym == "Left":
        mn = 50625; cnt+=360-howm
        crd = canvas.coords(dot_ov)
        if cnt>360: cnt -=360
        if cnt <= 90:
            #! 90
            xxx=sqrt(((cos(radians(cnt)))**2)*mn)
            yyy=sqrt(((sin(radians(cnt)))**2)*mn)
        
            canvas.coords( dot_ov, dstc( k+xxx , p-yyy ) )
            canvas.coords( sin_line_ov, k+xxx, p, k+xxx, p-yyy )
            canvas.coords( cos_line_ov, k, p, k+xxx, p )
            canvas.coords( gip_line_ov, k, p, k+xxx, p-yyy )
            canvas.coords( sin_text_ov, k+xxx, p-yyy )
            canvas.coords( cos_text_ov, k, p )
            canvas.coords( angel_text_ov, k+4, p-17 )
            canvas.itemconfigure( cos_text_ov, text="cos/a = {0}".format(round(cos(radians(cnt)),6)))
            canvas.itemconfigure( sin_text_ov, text="sin/a = {0}".format(round(sin(radians(cnt)),6)))
            canvas.itemconfigure( angel_text_ov, text="/a = {0}".format(cnt))
        elif cnt <= 180:
            #! 180
            xxx=sqrt(((cos(radians(cnt)))**2)*mn)
            yyy=sqrt(((sin(radians(cnt)))**2)*mn)
        
            canvas.coords( dot_ov, dstc( k-xxx , p-yyy ) )
            canvas.coords( sin_line_ov, k-xxx, p, k-xxx, p-yyy )
            canvas.coords( cos_line_ov, k, p, k-xxx, p )
            canvas.coords( gip_line_ov, k, p, k-xxx, p-yyy )
            canvas.coords( sin_text_ov, k-xxx, p-yyy )
            canvas.coords( cos_text_ov, k-xxx, p )
            canvas.coords( angel_text_ov, k-70, p-17 )
            canvas.itemconfigure( cos_text_ov, text="cos/a = {0}".format(round(cos(radians(cnt)),6)))
            canvas.itemconfigure( sin_text_ov, text="sin/a = {0}".format(round(sin(radians(cnt)),6)))
            canvas.itemconfigure( angel_text_ov, text="/a = {0}".format(cnt))
        elif cnt <= 270:
            #! 270
            xxx=sqrt(((cos(radians(cnt)))**2)*mn)
            yyy=sqrt(((sin(radians(cnt)))**2)*mn)
        
            canvas.coords( dot_ov, dstc( k-xxx , p+yyy ) )
            canvas.coords( sin_line_ov, k-xxx, p, k-xxx, p+yyy )
            canvas.coords( cos_line_ov, k, p, k-xxx, p )
            canvas.coords( gip_line_ov, k, p, k-xxx, p+yyy )
            canvas.coords( sin_text_ov, k-xxx, p+yyy )
            canvas.coords( cos_text_ov, k-xxx, p-18 )
            canvas.coords( angel_text_ov, k-70, p )
            canvas.itemconfigure( cos_text_ov, text="cos/a = {0}".format(round(cos(radians(cnt)),6)))
            canvas.itemconfigure( sin_text_ov, text="sin/a = {0}".format(round(sin(radians(cnt)),6)))
            canvas.itemconfigure( angel_text_ov, text="/a = {0}".format(cnt))
        elif cnt <= 360:
            #! 360
            xxx=sqrt(((cos(radians(cnt)))**2)*mn)
            yyy=sqrt(((sin(radians(cnt)))**2)*mn)
        
            canvas.coords( dot_ov, dstc( k+xxx , p+yyy ) )
            canvas.coords( sin_line_ov, k+xxx, p, k+xxx, p+yyy )
            canvas.coords( cos_line_ov, k, p, k+xxx, p )
            canvas.coords( gip_line_ov, k, p, k+xxx, p+yyy )
            canvas.coords( sin_text_ov, k+xxx, p+yyy )
            canvas.coords( angel_text_ov, k, p )
            canvas.itemconfigure( cos_text_ov, text="cos/a = {0}".format(round(cos(radians(cnt)),6)))
            canvas.itemconfigure( sin_text_ov, text="sin/a = {0}".format(round(sin(radians(cnt)),6)))
            canvas.itemconfigure( angel_text_ov, text="/a = {0}".format(cnt))
        

window.bind("<Right>", ovaldot)
window.bind("<Left>", ovaldot)

window.mainloop()
exit()
